@echo off
chcp 65001 >nul
echo ========================================
echo Tiny QA Windows 停止脚本
echo ========================================

REM 查找并停止Tiny QA进程
echo 🔍 查找Tiny QA进程...
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq python.exe" /fo csv ^| findstr "app.py"') do (
    echo 找到进程: %%i
    taskkill /pid %%i /f >nul 2>&1
    if errorlevel 1 (
        echo ❌ 停止进程失败
    ) else (
        echo ✅ 进程已停止
    )
)

REM 查找Flask进程
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq python.exe" /fo csv ^| findstr "flask"') do (
    echo 找到Flask进程: %%i
    taskkill /pid %%i /f >nul 2>&1
    if errorlevel 1 (
        echo ❌ 停止Flask进程失败
    ) else (
        echo ✅ Flask进程已停止
    )
)

REM 检查是否还有Python进程在运行
tasklist /fi "imagename eq python.exe" | findstr "app.py" >nul
if errorlevel 1 (
    echo ✅ Tiny QA 服务已停止
) else (
    echo ⚠️ 仍有Python进程在运行，请手动检查
    tasklist /fi "imagename eq python.exe"
)

echo.
echo 如需完全清理，请关闭所有相关终端窗口
pause 